/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * Se crea un objeto AJAX
 */
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

// JavaScript Document
function RegistroCrear(form,action,mensaje){
    try{
	var string="";	
	var i;
	ajax=nuevoAjax();
	ajax.open("POST", action);
	ajax.onreadystatechange=function() {
		if (ajax.readyState == 4){
			//alert(ajax.responseText);
			/*if(ajax.responseText != 4 && ajax.responseText != 1){
				alert("Ha ocurrido un error registrando el cliente. Intente nuevamente.");
				recargar('registrar.php');
			}else{*/
//                          alert(mensaje+" satisfactoriamente");
                        //}
			
		}
	}
	
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
	for(i=0;i<form.length;i++){
		if((form[i].type == "hidden" || form[i].type == "text" || form[i].type == "textarea" || form[i].type == "select-one") && !form[i].disabled && form[i].name != "cpYear" && form[i].name != "cpMonth" && form[i].name != "tipoclient")
			string += form[i].name+"="+form[i].value+"&";
		else{
			if(form[i].type == "radio" || form[i].type == "checkbox")
				if(form[i].checked)
					string += form[i].name+"="+form[i].value+"&";
		}
	}
	string = string.substring(0,string.length-1);
//	alert("action = "+action+"\n"+string);
	ajax.send(string);
	return false;
    }catch(e){
        alert(e.message);
        return false;
        
    }
}
    
    
    function registrar(string,action,mensaje){
    try{
       
	ajax=nuevoAjax();
	ajax.open("POST", action);
	ajax.onreadystatechange=function() {
		if (ajax.readyState == 4){
                  //alert(ajax.responseText);	
		}
	}
	
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
//	alert("action = "+action+"\nString = "+string);
	ajax.send(string);
	return false;
    }catch(e){
        alert(e);
        return false;
        
    }            
}

    function recargar(file){
	window.location = file;		
}
